home *** CD-ROM | disk | FTP | other *** search
- #include <Files.h>
- #include <StdLib.h>
- #include <Resources.h>
- #include <StandardFile.h>
- #include "ui.h"
-
- void CenterRect (Rect *r);
-
- static pascal Boolean source_filter (ParmBlkPtr pb)
- {
- char len = pb->fileParam.ioNamePtr [0];
- if (len >= 3
- && pb->fileParam.ioNamePtr [len] == 'l'
- && pb->fileParam.ioNamePtr [len - 1] == 'm'
- && pb->fileParam.ioNamePtr [len - 2] == '.'){
- return 0;
- }else{
- return 1;
- }
- }
-
- static pascal Boolean object_filter (ParmBlkPtr pb)
- {
- char len = pb->fileParam.ioNamePtr [0];
- if (len >= 3
- && pb->fileParam.ioNamePtr [len] == 'o'
- && pb->fileParam.ioNamePtr [len - 1] == 'z'
- && pb->fileParam.ioNamePtr [len - 2] == '.'){
- return 0;
- }else{
- return 1;
- }
- }
-
- extern char *get_wd_name (short wd_refnum, char *postfix);
-
- static char postfix [] = ":";
- static char nocd_template [] = "%s \"%s\";;";
- static char cd_template [] = "cd \"%s\"; %s \"%s\";;";
-
- void do_file (char *command, long type, pascal Boolean (*filter) (ParmBlkPtr))
- {
- DialogTHndl the_dialog;
- Point there;
- SFTypeList type_list;
- SFReply reply;
- short cur_vol;
- Rect sb = qd.screenBits.bounds;
- char *buf, *dir;
-
- the_dialog = (DialogTHndl) GetResource ('DLOG', getDlgID);
- if (the_dialog != nil && *the_dialog != nil){
- Rect *r = &(*the_dialog)->boundsRect;
-
- CenterRect (r);
- there.h = r->left;
- there.v = r->top;
- }else{
- there.h = 200;
- there.v = 100;
- }
- type_list [0] = type;
- SFGetFile (there, "\p", filter, 1, type_list, nil, &reply);
- if (!reply.good) return;
- p2cstr (reply.fName);
- GetVol (NULL, &cur_vol);
- if (cur_vol == reply.vRefNum){
- buf = malloc (sizeof (nocd_template) - 4
- + strlen (command)
- + strlen (reply.fName));
- if (buf == NULL) return;
- sprintf (buf, nocd_template, command, reply.fName);
- }else{
- dir = get_wd_name (reply.vRefNum, postfix);
- buf = malloc (sizeof (cd_template) - 6
- + strlen (dir)
- + strlen (command)
- + strlen (reply.fName));
- if (buf == NULL) return;
- sprintf (buf, cd_template, dir, command, reply.fName);
- if (dir != postfix) free (dir - 1); /* cf.get_wd_name */
- }
- send_to_caml (buf);
- free (buf);
- }
-
- void do_include (void)
- {
- do_file ("include", 'TEXT', source_filter);
- }
-
- void do_compile (void)
- {
- do_file ("compile", 'TEXT', source_filter);
- }
-
- void do_load (void)
- {
- do_file ("load", 'TEXT', source_filter);
- }
-
- void do_load_object (void)
- {
- do_file ("load_object", '\0\0\0\0', object_filter);
- }
-
- void do_gc (void)
- {
- send_to_caml ("gc();gc();;");
- }
-